+2000-09-25 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtktextview.c: Draw the focus, and leave space to do so.
+
+ * gtk/gtktexttypes.c: Remove Latin1 conversion stuff
+
+ * gtk/gtktextbtree.c (gtk_text_btree_node_remove_data):
+ Fix a bug when removing node data, we didn't properly
+ re-splice the linked list after removing the data.
+
+ * gtk/gtktextview.c (gtk_text_view_key_press_event): Pass through
+ GDK_Tab as literal tab, Ctrl-Tab to tab to focus widget
+
+ * gtk/gtktextbuffer.c (selection_received): fix g_convert usage
+
+ * gtk/gtktextlayout.c (set_para_values): Set tab array
+ for the layout from the GtkTextTag.
+
+ * gtk/gtktexttypes.h: delete tab and search cruft,
+ remove g_convert() in favor of GLib version
+
+ * gtk/gtktexttypes.c: remove tab implementation from here,
+ move to Pango
+
+ * gtk/gtktexttag.h, gtk/gtktexttag.c: Implement
+ tab stuff using new PangoTabArray from Pango
+
+ * gtk/gtktexttag.c (gtk_text_attributes_fill_from_tags): Remove
+ unused border_width stuff
+
Thu Sep 14 12:21:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtktexttypes.[ch]: Remove g_convert (moved to
+2000-09-25 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtktextview.c: Draw the focus, and leave space to do so.
+
+ * gtk/gtktexttypes.c: Remove Latin1 conversion stuff
+
+ * gtk/gtktextbtree.c (gtk_text_btree_node_remove_data):
+ Fix a bug when removing node data, we didn't properly
+ re-splice the linked list after removing the data.
+
+ * gtk/gtktextview.c (gtk_text_view_key_press_event): Pass through
+ GDK_Tab as literal tab, Ctrl-Tab to tab to focus widget
+
+ * gtk/gtktextbuffer.c (selection_received): fix g_convert usage
+
+ * gtk/gtktextlayout.c (set_para_values): Set tab array
+ for the layout from the GtkTextTag.
+
+ * gtk/gtktexttypes.h: delete tab and search cruft,
+ remove g_convert() in favor of GLib version
+
+ * gtk/gtktexttypes.c: remove tab implementation from here,
+ move to Pango
+
+ * gtk/gtktexttag.h, gtk/gtktexttag.c: Implement
+ tab stuff using new PangoTabArray from Pango
+
+ * gtk/gtktexttag.c (gtk_text_attributes_fill_from_tags): Remove
+ unused border_width stuff
+
Thu Sep 14 12:21:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtktexttypes.[ch]: Remove g_convert (moved to
+2000-09-25 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtktextview.c: Draw the focus, and leave space to do so.
+
+ * gtk/gtktexttypes.c: Remove Latin1 conversion stuff
+
+ * gtk/gtktextbtree.c (gtk_text_btree_node_remove_data):
+ Fix a bug when removing node data, we didn't properly
+ re-splice the linked list after removing the data.
+
+ * gtk/gtktextview.c (gtk_text_view_key_press_event): Pass through
+ GDK_Tab as literal tab, Ctrl-Tab to tab to focus widget
+
+ * gtk/gtktextbuffer.c (selection_received): fix g_convert usage
+
+ * gtk/gtktextlayout.c (set_para_values): Set tab array
+ for the layout from the GtkTextTag.
+
+ * gtk/gtktexttypes.h: delete tab and search cruft,
+ remove g_convert() in favor of GLib version
+
+ * gtk/gtktexttypes.c: remove tab implementation from here,
+ move to Pango
+
+ * gtk/gtktexttag.h, gtk/gtktexttag.c: Implement
+ tab stuff using new PangoTabArray from Pango
+
+ * gtk/gtktexttag.c (gtk_text_attributes_fill_from_tags): Remove
+ unused border_width stuff
+
Thu Sep 14 12:21:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtktexttypes.[ch]: Remove g_convert (moved to
+2000-09-25 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtktextview.c: Draw the focus, and leave space to do so.
+
+ * gtk/gtktexttypes.c: Remove Latin1 conversion stuff
+
+ * gtk/gtktextbtree.c (gtk_text_btree_node_remove_data):
+ Fix a bug when removing node data, we didn't properly
+ re-splice the linked list after removing the data.
+
+ * gtk/gtktextview.c (gtk_text_view_key_press_event): Pass through
+ GDK_Tab as literal tab, Ctrl-Tab to tab to focus widget
+
+ * gtk/gtktextbuffer.c (selection_received): fix g_convert usage
+
+ * gtk/gtktextlayout.c (set_para_values): Set tab array
+ for the layout from the GtkTextTag.
+
+ * gtk/gtktexttypes.h: delete tab and search cruft,
+ remove g_convert() in favor of GLib version
+
+ * gtk/gtktexttypes.c: remove tab implementation from here,
+ move to Pango
+
+ * gtk/gtktexttag.h, gtk/gtktexttag.c: Implement
+ tab stuff using new PangoTabArray from Pango
+
+ * gtk/gtktexttag.c (gtk_text_attributes_fill_from_tags): Remove
+ unused border_width stuff
+
Thu Sep 14 12:21:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtktexttypes.[ch]: Remove g_convert (moved to
+2000-09-25 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtktextview.c: Draw the focus, and leave space to do so.
+
+ * gtk/gtktexttypes.c: Remove Latin1 conversion stuff
+
+ * gtk/gtktextbtree.c (gtk_text_btree_node_remove_data):
+ Fix a bug when removing node data, we didn't properly
+ re-splice the linked list after removing the data.
+
+ * gtk/gtktextview.c (gtk_text_view_key_press_event): Pass through
+ GDK_Tab as literal tab, Ctrl-Tab to tab to focus widget
+
+ * gtk/gtktextbuffer.c (selection_received): fix g_convert usage
+
+ * gtk/gtktextlayout.c (set_para_values): Set tab array
+ for the layout from the GtkTextTag.
+
+ * gtk/gtktexttypes.h: delete tab and search cruft,
+ remove g_convert() in favor of GLib version
+
+ * gtk/gtktexttypes.c: remove tab implementation from here,
+ move to Pango
+
+ * gtk/gtktexttag.h, gtk/gtktexttag.c: Implement
+ tab stuff using new PangoTabArray from Pango
+
+ * gtk/gtktexttag.c (gtk_text_attributes_fill_from_tags): Remove
+ unused border_width stuff
+
Thu Sep 14 12:21:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtktexttypes.[ch]: Remove g_convert (moved to
+2000-09-25 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtktextview.c: Draw the focus, and leave space to do so.
+
+ * gtk/gtktexttypes.c: Remove Latin1 conversion stuff
+
+ * gtk/gtktextbtree.c (gtk_text_btree_node_remove_data):
+ Fix a bug when removing node data, we didn't properly
+ re-splice the linked list after removing the data.
+
+ * gtk/gtktextview.c (gtk_text_view_key_press_event): Pass through
+ GDK_Tab as literal tab, Ctrl-Tab to tab to focus widget
+
+ * gtk/gtktextbuffer.c (selection_received): fix g_convert usage
+
+ * gtk/gtktextlayout.c (set_para_values): Set tab array
+ for the layout from the GtkTextTag.
+
+ * gtk/gtktexttypes.h: delete tab and search cruft,
+ remove g_convert() in favor of GLib version
+
+ * gtk/gtktexttypes.c: remove tab implementation from here,
+ move to Pango
+
+ * gtk/gtktexttag.h, gtk/gtktexttag.c: Implement
+ tab stuff using new PangoTabArray from Pango
+
+ * gtk/gtktexttag.c (gtk_text_attributes_fill_from_tags): Remove
+ unused border_width stuff
+
Thu Sep 14 12:21:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtktexttypes.[ch]: Remove g_convert (moved to
+2000-09-25 Havoc Pennington <hp@redhat.com>
+
+ * gtk/gtktextview.c: Draw the focus, and leave space to do so.
+
+ * gtk/gtktexttypes.c: Remove Latin1 conversion stuff
+
+ * gtk/gtktextbtree.c (gtk_text_btree_node_remove_data):
+ Fix a bug when removing node data, we didn't properly
+ re-splice the linked list after removing the data.
+
+ * gtk/gtktextview.c (gtk_text_view_key_press_event): Pass through
+ GDK_Tab as literal tab, Ctrl-Tab to tab to focus widget
+
+ * gtk/gtktextbuffer.c (selection_received): fix g_convert usage
+
+ * gtk/gtktextlayout.c (set_para_values): Set tab array
+ for the layout from the GtkTextTag.
+
+ * gtk/gtktexttypes.h: delete tab and search cruft,
+ remove g_convert() in favor of GLib version
+
+ * gtk/gtktexttypes.c: remove tab implementation from here,
+ move to Pango
+
+ * gtk/gtktexttag.h, gtk/gtktexttag.c: Implement
+ tab stuff using new PangoTabArray from Pango
+
+ * gtk/gtktexttag.c (gtk_text_attributes_fill_from_tags): Remove
+ unused border_width stuff
+
Thu Sep 14 12:21:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtktexttypes.[ch]: Remove g_convert (moved to
+<!-- ##### SECTION ./tmpl/from-drawables.sgml:Title ##### -->
+Drawables to Pixbufs
+
+
<!-- ##### USER_FUNCTION GdkPixbufLastUnref ##### -->
<para>
A function of this type can be used to override the default
@pixbuf: The pixbuf that is losing its last reference.
@data: User closure data.
-<!-- ##### SECTION ./tmpl/from-drawables.sgml:Title ##### -->
-Drawables to Pixbufs
-
-
<!-- ##### ARG GnomeCanvasPixbuf:height_pixels ##### -->
<para>
if (nd->view_id == view_id)
break;
+ prev = nd;
nd = nd->next;
}
else
; /* FIXME Delete selected chars and give up X selection */
}
-#endif
-
-
+#endif
+
if (request_data->interactive)
gtk_text_buffer_insert_interactive (buffer, &insert_point,
str, -1, request_data->default_editable);
pango_layout_set_alignment (display->layout, pango_align);
pango_layout_set_spacing (display->layout, style->pixels_inside_wrap * PANGO_SCALE);
+ if (style->tabs)
+ pango_layout_set_tabs (display->layout, style->tabs);
+
display->top_margin = style->pixels_above_lines;
display->height = style->pixels_above_lines + style->pixels_below_lines;
display->bottom_margin = style->pixels_below_lines;
gint width;
gint height;
+ /* Pixel offsets from the left and from the top to be used when we
+ * draw; these allow us to create left/top margins. We don't need
+ * anything special for bottom/right margins, because those don't
+ * affect drawing.
+ */
+ /* gint left_edge; */
+ /* gint top_edge; */
+
GtkTextBuffer *buffer;
/* Default style used if no tags override it */
#include "gtkmain.h"
#include <stdlib.h>
+#include <string.h>
enum {
EVENT,
ARG_OFFSET,
ARG_BG_FULL_HEIGHT,
ARG_LANGUAGE,
+ ARG_TABS,
/* Whether-a-style-arg-is-set args */
ARG_BACKGROUND_SET,
ARG_OFFSET_SET,
ARG_BG_FULL_HEIGHT_SET,
ARG_LANGUAGE_SET,
+ ARG_TABS_SET,
LAST_ARG
};
GTK_ARG_READWRITE, ARG_UNDERLINE);
gtk_object_add_arg_type ("GtkTextTag::wrap_mode", GTK_TYPE_ENUM,
GTK_ARG_READWRITE, ARG_WRAP_MODE);
+ gtk_object_add_arg_type ("GtkTextTag::tabs", GTK_TYPE_POINTER,
+ GTK_ARG_READWRITE, ARG_TABS);
/* Style args are set or not */
gtk_object_add_arg_type ("GtkTextTag::background_set", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_UNDERLINE_SET);
gtk_object_add_arg_type ("GtkTextTag::wrap_mode_set", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_WRAP_MODE_SET);
+ gtk_object_add_arg_type ("GtkTextTag::tabs_set", GTK_TYPE_BOOL,
+ GTK_ARG_READWRITE, ARG_TABS_SET);
+
signals[EVENT] =
gtk_signal_new ("event",
tkxt_tag->language_set = TRUE;
tkxt_tag->values->language = g_strdup (GTK_VALUE_STRING(*arg));
break;
+
+ case ARG_TABS:
+ tkxt_tag->tabs_set = TRUE;
+
+ if (tkxt_tag->values->tabs)
+ pango_tab_array_free (tkxt_tag->values->tabs);
+
+ tkxt_tag->values->tabs =
+ pango_tab_array_copy (GTK_VALUE_POINTER (*arg));
+
+ size_changed = TRUE;
+ break;
/* Whether the value should be used... */
tkxt_tag->language_set = GTK_VALUE_BOOL(*arg);
size_changed = TRUE;
break;
+
+ case ARG_TABS_SET:
+ tkxt_tag->tabs_set = GTK_VALUE_BOOL (*arg);
+ size_changed = TRUE;
+ break;
default:
g_assert_not_reached();
case ARG_LANGUAGE:
GTK_VALUE_STRING(*arg) = g_strdup (tag->values->language);
break;
+
+ case ARG_TABS:
+ GTK_VALUE_POINTER (*arg) = tag->values->tabs ?
+ pango_tab_array_copy (tag->values->tabs) : NULL;
+ break;
case ARG_BACKGROUND_SET:
case ARG_BACKGROUND_GDK_SET:
case ARG_LANGUAGE_SET:
GTK_VALUE_BOOL(*arg) = tag->language_set;
break;
+
+ case ARG_TABS_SET:
+ GTK_VALUE_BOOL (*arg) = tag->tabs_set;
+ break;
case ARG_BACKGROUND:
case ARG_FOREGROUND:
void
gtk_text_attributes_copy(GtkTextAttributes *src,
- GtkTextAttributes *dest)
+ GtkTextAttributes *dest)
{
guint orig_refcount;
if (src->appearance.fg_stipple)
gdk_bitmap_ref(src->appearance.fg_stipple);
- if (src->tab_array)
- gtk_text_view_tab_array_ref(src->tab_array);
-
/* Remove refs */
if (dest->appearance.bg_stipple)
if (dest->appearance.fg_stipple)
gdk_bitmap_unref(dest->appearance.fg_stipple);
- if (dest->tab_array)
- gtk_text_view_tab_array_unref(dest->tab_array);
-
/* Copy */
orig_refcount = dest->refcount;
*dest = *src;
dest->font_desc = pango_font_description_copy (src->font_desc);
+
+ if (src->tabs)
+ dest->tabs = pango_tab_array_copy (src->tabs);
+
dest->language = g_strdup (src->language);
dest->refcount = orig_refcount;
if (values->appearance.fg_stipple)
gdk_bitmap_unref(values->appearance.fg_stipple);
- if (values->tab_array)
- gtk_text_view_tab_array_unref(values->tab_array);
+ if (values->tabs)
+ pango_tab_array_free (values->tabs);
if (values->language)
g_free (values->language);
dest->appearance.bg_color = vals->appearance.bg_color;
dest->appearance.draw_bg = TRUE;
- }
-
- if (tag->border_width_set)
- dest->border_width = vals->border_width;
+ }
if (tag->relief_set)
dest->relief = vals->relief;
if (tag->pixels_inside_wrap_set)
dest->pixels_inside_wrap = vals->pixels_inside_wrap;
- if (tag->tab_array_set)
+ if (tag->tabs_set)
{
- gtk_text_view_tab_array_ref(vals->tab_array);
- if (dest->tab_array)
- gtk_text_view_tab_array_unref(dest->tab_array);
- dest->tab_array = vals->tab_array;
+ if (dest->tabs)
+ pango_tab_array_free (dest->tabs);
+ dest->tabs = pango_tab_array_copy (vals->tabs);
}
if (tag->wrap_mode_set)
typedef struct _GtkTextIter GtkTextIter;
typedef struct _GtkTextBTreeNode GtkTextBTreeNode;
typedef struct _GtkTextTagTable GtkTextTagTable;
-typedef struct _GtkTextTabArray GtkTextTabArray;
-typedef enum {
+typedef enum
+{
GTK_WRAPMODE_NONE,
GTK_WRAPMODE_CHAR,
GTK_WRAPMODE_WORD
GtkTextAttributes *values;
- /*
- Flags for whether a given value is set; if a value is unset, then
- this tag does not affect it. */
+ /* Flags for whether a given value is set; if a value is unset, then
+ * this tag does not affect it.
+ */
guint bg_color_set : 1;
- guint border_width_set : 1;
guint relief_set : 1;
guint bg_stipple_set : 1;
guint fg_color_set : 1;
guint pixels_above_lines_set : 1;
guint pixels_below_lines_set : 1;
guint pixels_inside_wrap_set : 1;
- guint tab_array_set : 1;
+ guint tabs_set : 1;
guint underline_set : 1;
guint wrap_mode_set : 1;
guint bg_full_height_set : 1;
/* Whether to use background-related values; this is irrelevant for
* the values struct when in a tag, but is used for the composite
* values struct; it's true if any of the tags being composited
- * had background stuff set. */
+ * had background stuff set.
+ */
guint draw_bg : 1;
/* This is only used when we are actually laying out and rendering
GtkTextAppearance appearance;
- gint border_width;
GtkShadowType relief;
GtkJustification justify;
GtkTextDirection direction;
gint pixels_inside_wrap;
- GtkTextTabArray *tab_array;
+ PangoTabArray *tabs;
GtkWrapMode wrap_mode; /* How to handle wrap-around for this tag.
* Must be GTK_WRAPMODE_CHAR,
guint invisible : 1;
/* Background is fit to full line height rather than
- * baseline +/- ascent/descent (font height) */
+ * baseline +/- ascent/descent (font height)
+ */
guint bg_full_height : 1;
/* can edit this text */
void gtk_text_attributes_unref (GtkTextAttributes *values);
void gtk_text_attributes_ref (GtkTextAttributes *values);
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
#include "gtktexttypes.h"
-
-/*
- * Tab array
- */
-
-GtkTextTabArray*
-gtk_text_view_tab_array_new(guint size)
-{
- GtkTextTabArray *array;
-
- array = g_new0(GtkTextTabArray, 1);
-
- array->refcount = 1;
- array->numTabs = size;
- array->tabs = g_new0(GtkTextTab, size);
-
- return array;
-}
-
-void
-gtk_text_view_tab_array_ref(GtkTextTabArray *tab_array)
-{
- g_return_if_fail(tab_array != NULL);
-
- tab_array->refcount += 1;
-}
-
-void
-gtk_text_view_tab_array_unref(GtkTextTabArray *tab_array)
-{
- g_return_if_fail(tab_array != NULL);
- g_return_if_fail(tab_array->refcount > 0);
-
- tab_array->refcount -= 1;
-
- if (tab_array->refcount == 0)
- {
- g_free(tab_array->tabs);
- g_free(tab_array);
- }
-}
-
/* These are used to represent embedded non-character objects
* if you return a string representation of a text buffer
*/
{
return inline_byte_begins_utf8_char(byte);
}
-
typedef struct _GtkTextLineSegment GtkTextLineSegment;
typedef struct _GtkTextLineSegmentClass GtkTextLineSegmentClass;
typedef struct _GtkTextToggleBody GtkTextToggleBody;
-typedef struct _GtkTextViewSearch GtkTextViewSearch;
-typedef struct _GtkTextTab GtkTextTab;
-typedef struct _GtkTextViewStyle GtkTextViewStyle;
typedef struct _GtkTextMarkBody GtkTextMarkBody;
-/*
- * Search
- */
-
-/*
- * The data structure below is used for searching a B-tree for transitions
- * on a single tag (or for all tag transitions). No code outside of
- * tkTextBTree.c should ever modify any of the fields in these structures,
- * but it's OK to use them for read-only information.
- */
-
-struct _GtkTextViewSearch {
- GtkTextBTree *tree;
-
- GtkTextIter curIndex; /* Position of last tag transition
- * returned by gtk_text_btree_next_tag, or
- * index of start of segment
- * containing starting position for
- * search if gtk_text_btree_next_tag hasn't
- * been called yet, or same as
- * stopIndex if search is over. */
-
- GtkTextLineSegment *segPtr; /* Actual tag segment returned
- by last call to
- gtk_text_btree_next_tag,
- or NULL if
- gtk_text_btree_next_tag
- hasn't returned anything
- yet. */
-
- GtkTextLineSegment *lastPtr; /* Stop search before just before
- * considering this segment. */
- GtkTextTag *tag; /* Tag to search for (or tag found, if
- * allTags is non-zero). */
- int linesLeft; /* Lines left to search (including
- * curIndex and stopIndex). When
- * this becomes <= 0 the search is
- * over. */
- int allTags; /* Non-zero means ignore tag check:
- * search for transitions on all
- * tags. */
-};
-
-/*
- * The following data structure describes a single tab stop.
- */
-
-typedef enum {
- GTK_TEXT_TAB_LEFT,
- GTK_TEXT_TAB_RIGHT,
- GTK_TEXT_TAB_CENTER,
- GTK_TEXT_TAB_NUMERIC
-} GtkTextTabAlign;
-
-struct _GtkTextTab {
- int location; /* Offset in pixels of this tab stop
- * from the left margin (lmargin2) of
- * the text. */
- GtkTextTabAlign alignment; /* Where the tab stop appears relative
- * to the text. */
-};
-
-struct _GtkTextTabArray {
- guint refcount;
- int numTabs; /* Number of tab stops. */
- GtkTextTab *tabs;
-};
-
-GtkTextTabArray *gtk_text_view_tab_array_new (guint size);
-void gtk_text_view_tab_array_ref (GtkTextTabArray *tab_array);
-void gtk_text_view_tab_array_unref (GtkTextTabArray *tab_array);
-
/*
* Declarations for variables shared among the text-related files:
*/
#include "gtktexttypes.h"
#include <string.h>
+#define FOCUS_RECT_WIDTH 10
+#if 0
+#define SCREEN_WIDTH(widget) (MAX (GTK_WIDGET(widget)->allocation.width - FOCUS_RECT_WIDTH*2, 0))
+#define SCREEN_HEIGHT(widget) (MAX (GTK_WIDGET(widget)->allocation.height - FOCUS_RECT_WIDTH*2, 0))
+#else
+#define SCREEN_WIDTH(widget) GTK_WIDGET(widget)->allocation.width
+#define SCREEN_HEIGHT(widget) GTK_WIDGET(widget)->allocation.height
+#endif
+
enum {
MOVE,
SET_ANCHOR,
GdkRectangle *area);
static gint gtk_text_view_expose_event (GtkWidget *widget,
GdkEventExpose *expose);
+static void gtk_text_view_draw_focus (GtkWidget *widget);
/* Source side drag signals */
static void gtk_text_view_get_first_para_iter (GtkTextView *text_view,
GtkTextIter *iter);
static void gtk_text_view_scroll_calc_now (GtkTextView *text_view);
-static void gtk_text_view_set_values_from_style (GtkTextView *text_view,
- GtkTextAttributes *values,
- GtkStyle *style);
+static void gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
+ GtkTextAttributes *values,
+ GtkStyle *style);
static void gtk_text_view_ensure_layout (GtkTextView *text_view);
static void gtk_text_view_destroy_layout (GtkTextView *text_view);
static void gtk_text_view_start_selection_drag (GtkTextView *text_view,
static void gtk_text_view_start_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
-static void gtk_text_view_value_changed (GtkAdjustment *adj,
- GtkTextView *view);
+static void gtk_text_view_value_changed (GtkAdjustment *adj,
+ GtkTextView *view);
static void gtk_text_view_commit_handler (GtkIMContext *context,
const gchar *str,
GtkTextView *text_view);
widget_class->motion_notify_event = gtk_text_view_motion_event;
widget_class->expose_event = gtk_text_view_expose_event;
widget_class->draw = gtk_text_view_draw;
-
+ widget_class->draw_focus = gtk_text_view_draw_focus;
+
widget_class->drag_begin = gtk_text_view_drag_begin;
widget_class->drag_end = gtk_text_view_drag_end;
widget_class->drag_data_get = gtk_text_view_drag_data_get;
screen.x = current_x_scroll;
screen.y = current_y_scroll;
- screen.width = widget->allocation.width;
- screen.height = widget->allocation.height;
+ screen.width = SCREEN_WIDTH (widget);
+ screen.height = SCREEN_HEIGHT (widget);
{
/* Clamp margin so it's not too large. */
{
visible_rect->x = text_view->xoffset;
visible_rect->y = text_view->yoffset;
- visible_rect->width = widget->allocation.width;
- visible_rect->height = widget->allocation.height;
+ visible_rect->width = SCREEN_WIDTH (widget);
+ visible_rect->height = SCREEN_HEIGHT (widget);
}
}
gtk_text_view_ensure_layout (text_view);
gtk_text_layout_set_screen_width (text_view->layout,
- GTK_WIDGET (text_view)->allocation.width);
+ SCREEN_WIDTH (text_view));
gtk_text_view_validate_onscreen (text_view);
gtk_text_view_scroll_calc_now (text_view);
- /* Now adjust the value of the adjustment to keep the cursor at the same place in
- * the buffer
- */
+ /* Now adjust the value of the adjustment to keep the cursor at the
+ * same place in the buffer
+ */
gtk_text_view_get_first_para_iter (text_view, &first_para);
gtk_text_layout_get_line_yrange (text_view->layout, &first_para, &y, NULL);
yoffset_changed = TRUE;
}
- text_view->hadjustment->page_size = allocation->width;
- text_view->hadjustment->page_increment = allocation->width / 2;
+ text_view->hadjustment->page_size = SCREEN_WIDTH (text_view);
+ text_view->hadjustment->page_increment = SCREEN_WIDTH (text_view) / 2;
text_view->hadjustment->lower = 0;
- text_view->hadjustment->upper = MAX (allocation->width, text_view->width);
+ text_view->hadjustment->upper = MAX (SCREEN_WIDTH (text_view),
+ text_view->width);
gtk_signal_emit_by_name (GTK_OBJECT (text_view->hadjustment), "changed");
- text_view->vadjustment->page_size = allocation->height;
- text_view->vadjustment->page_increment = allocation->height / 2;
+ text_view->vadjustment->page_size = SCREEN_HEIGHT (text_view);
+ text_view->vadjustment->page_increment = SCREEN_HEIGHT (text_view) / 2;
text_view->vadjustment->lower = 0;
- text_view->vadjustment->upper = MAX (allocation->height, text_view->height);
+ text_view->vadjustment->upper = MAX (SCREEN_HEIGHT (text_view),
+ text_view->height);
gtk_signal_emit_by_name (GTK_OBJECT (text_view->vadjustment), "changed");
if (yoffset_changed)
{
GtkWidget *widget = GTK_WIDGET (text_view);
- if (widget->allocation.height > 0)
+ if (SCREEN_HEIGHT (widget) > 0)
{
GtkTextIter first_para;
gtk_text_view_get_first_para_iter (text_view, &first_para);
gtk_text_layout_validate_yrange (text_view->layout,
&first_para,
- 0, text_view->first_para_pixels + widget->allocation.height);
+ 0,
+ text_view->first_para_pixels +
+ SCREEN_HEIGHT (widget));
}
}
gdk_window_set_background (text_view->bin_window,
&widget->style->base[GTK_WIDGET_STATE (widget)]);
- gtk_text_view_set_values_from_style (text_view, text_view->layout->default_style, widget->style);
+ gtk_text_view_set_attributes_from_style (text_view, text_view->layout->default_style, widget->style);
gtk_text_layout_default_style_changed (text_view->layout);
}
}
0);
return TRUE;
}
+ /* Pass through Tab as literal tab, unless Control is held down */
+ else if (event->keyval == GDK_Tab && !(event->state & GDK_CONTROL_MASK))
+ {
+ gtk_text_buffer_insert_interactive_at_cursor (text_view->buffer, "\t", 1,
+ text_view->editable);
+ gtk_text_view_scroll_to_mark (text_view,
+ gtk_text_buffer_get_mark (text_view->buffer,
+ "insert"),
+ 0);
+ return TRUE;
+ }
else
return FALSE;
}
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
-
+ gtk_widget_draw_focus (widget);
+
if (text_view->cursor_visible && text_view->layout)
{
gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
-
+ gtk_widget_draw_focus (widget);
+
if (text_view->cursor_visible && text_view->layout)
{
gtk_text_layout_set_cursor_visible (text_view->layout, FALSE);
gtk_text_layout_draw (text_view->layout,
widget,
text_view->bin_window,
- text_view->xoffset, text_view->yoffset,
+ text_view->xoffset,
+ text_view->yoffset,
area->x, area->y,
area->width, area->height);
}
return TRUE;
}
+static void
+gtk_text_view_draw_focus (GtkWidget *widget)
+{
+ if (GTK_WIDGET_DRAWABLE (widget))
+ {
+ if (GTK_WIDGET_HAS_FOCUS (widget))
+ {
+
+ gtk_paint_focus (widget->style, widget->window,
+ NULL, widget, "textview",
+ 0, 0,
+ widget->allocation.width - 1,
+ widget->allocation.height - 1);
+ }
+ }
+}
+
/*
* Blink!
*/
gtk_text_layout_validate_yrange (text_view->layout, &anchor, y0, y1);
-
gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
newval = adj->value;
+
newval += count * adj->page_increment;
cursor_y_pos += newval - adj->value;
in case you want to do a continuous slow scroll. */
#define SLOW_SCROLL_TH 7
if (x >= (0 - SLOW_SCROLL_TH) &&
- x < (GTK_WIDGET (text_view)->allocation.width + SLOW_SCROLL_TH) &&
+ x < (SCREEN_WIDTH (text_view) + SLOW_SCROLL_TH) &&
y >= (0 - SLOW_SCROLL_TH) &&
- y < (GTK_WIDGET (text_view)->allocation.height + SLOW_SCROLL_TH))
+ y < (SCREEN_HEIGHT (text_view) + SLOW_SCROLL_TH))
{
adjust = 0;
in_threshold = TRUE;
gtk_text_view_scroll_calc_now (GtkTextView *text_view)
{
gint width = 0, height = 0;
- GtkWidget *widget = GTK_WIDGET (text_view);
gtk_text_view_ensure_layout (text_view);
gtk_text_layout_set_screen_width (text_view->layout,
- widget->allocation.width);
+ SCREEN_WIDTH (text_view));
gtk_text_layout_get_size (text_view->layout, &width, &height);
text_view->height = height;
gtk_text_view_set_adjustment_upper (get_hadjustment (text_view),
- MAX (widget->allocation.width, width));
+ MAX (SCREEN_WIDTH (text_view), width));
gtk_text_view_set_adjustment_upper (get_vadjustment (text_view),
- MAX (widget->allocation.height, height));
+ MAX (SCREEN_HEIGHT (text_view), height));
/* hadj/vadj exist since we called get_hadjustment/get_vadjustment above */
our allocation minus one step, and a step is
1/10 of our allocation. */
text_view->hadjustment->step_increment =
- GTK_WIDGET (text_view)->allocation.width/10.0;
+ SCREEN_WIDTH (text_view) / 10.0;
text_view->hadjustment->page_increment =
- GTK_WIDGET (text_view)->allocation.width *0.9;
+ SCREEN_WIDTH (text_view) * 0.9;
text_view->vadjustment->step_increment =
- GTK_WIDGET (text_view)->allocation.height/10.0;
+ SCREEN_HEIGHT (text_view) / 10.0;
text_view->vadjustment->page_increment =
- GTK_WIDGET (text_view)->allocation.height *0.9;
+ SCREEN_HEIGHT (text_view) * 0.9;
}
}
static void
-gtk_text_view_set_values_from_style (GtkTextView *text_view,
- GtkTextAttributes *values,
- GtkStyle *style)
+gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
+ GtkTextAttributes *values,
+ GtkStyle *style)
{
values->appearance.bg_color = style->base[GTK_STATE_NORMAL];
values->appearance.fg_color = style->fg[GTK_STATE_NORMAL];
style = gtk_text_attributes_new ();
gtk_widget_ensure_style (widget);
- gtk_text_view_set_values_from_style (text_view, style, widget->style);
+ gtk_text_view_set_attributes_from_style (text_view,
+ style, widget->style);
style->pixels_above_lines = 2;
style->pixels_below_lines = 2;
the selection. */
gint margin;
- margin = MIN (widget->allocation.width, widget->allocation.height);
+ margin = MIN (SCREEN_WIDTH (widget), SCREEN_HEIGHT (widget));
margin /= 5;
gtk_text_view_scroll_to_mark_adjusted (text_view,
drag_target_mark);
str = gtk_selection_data_get_text (selection_data);
+
if (str)
{
gtk_text_buffer_insert_interactive (text_view->buffer,
void (* paste_clipboard) (GtkTextView *text_view);
/* overwrite */
void (* toggle_overwrite) (GtkTextView *text_view);
- void (*set_scroll_adjustments) (GtkTextView *text_view,
+ void (* set_scroll_adjustments) (GtkTextView *text_view,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
};
gint untitled_serial;
GtkTextTag *not_editable_tag;
GtkTextTag *found_text_tag;
+ GtkTextTag *custom_tabs_tag;
};
struct _View
}
}
+
+static void
+do_apply_tabs (gpointer callback_data,
+ guint callback_action,
+ GtkWidget *widget)
+{
+ View *view = view_from_widget (widget);
+ GtkTextIter start;
+ GtkTextIter end;
+
+ if (gtk_text_buffer_get_selection_bounds (view->buffer->buffer,
+ &start, &end))
+ {
+ if (callback_action)
+ {
+ gtk_text_buffer_remove_tag (view->buffer->buffer,
+ view->buffer->custom_tabs_tag,
+ &start, &end);
+ }
+ else
+ {
+ gtk_text_buffer_apply_tag (view->buffer->buffer,
+ view->buffer->custom_tabs_tag,
+ &start, &end);
+ }
+ }
+}
+
static void
dialog_response_callback (GtkWidget *dialog, gint response_id, gpointer data)
{
{ "/_Attributes", NULL, 0, 0, "<Branch>" },
{ "/Attributes/Editable", NULL, do_apply_editable, TRUE, NULL },
{ "/Attributes/Not editable", NULL, do_apply_editable, FALSE, NULL },
+ { "/Attributes/Custom tabs", NULL, do_apply_tabs, FALSE, NULL },
+ { "/Attributes/Default tabs", NULL, do_apply_tabs, TRUE, NULL },
{ "/_Test", NULL, 0, 0, "<Branch>" },
{ "/Test/_Example", NULL, do_example, 0, NULL },
};
create_buffer (void)
{
Buffer *buffer;
-
+ PangoTabArray *tabs;
+
buffer = g_new (Buffer, 1);
buffer->buffer = gtk_text_buffer_new (NULL);
buffer->found_text_tag = gtk_text_buffer_create_tag (buffer->buffer, NULL);
gtk_object_set (GTK_OBJECT (buffer->found_text_tag),
"foreground", "red", NULL);
+
+ tabs = pango_tab_array_new_with_defaults (4,
+ TRUE,
+ PANGO_TAB_LEFT, 10,
+ PANGO_TAB_LEFT, 30,
+ PANGO_TAB_LEFT, 60,
+ PANGO_TAB_LEFT, 120);
+
+ buffer->custom_tabs_tag = gtk_text_buffer_create_tag (buffer->buffer, NULL);
+ gtk_object_set (GTK_OBJECT (buffer->custom_tabs_tag),
+ "tabs", tabs,
+ "foreground", "green", NULL);
+
+ pango_tab_array_free (tabs);
buffers = g_slist_prepend (buffers, buffer);
gint untitled_serial;
GtkTextTag *not_editable_tag;
GtkTextTag *found_text_tag;
+ GtkTextTag *custom_tabs_tag;
};
struct _View
}
}
+
+static void
+do_apply_tabs (gpointer callback_data,
+ guint callback_action,
+ GtkWidget *widget)
+{
+ View *view = view_from_widget (widget);
+ GtkTextIter start;
+ GtkTextIter end;
+
+ if (gtk_text_buffer_get_selection_bounds (view->buffer->buffer,
+ &start, &end))
+ {
+ if (callback_action)
+ {
+ gtk_text_buffer_remove_tag (view->buffer->buffer,
+ view->buffer->custom_tabs_tag,
+ &start, &end);
+ }
+ else
+ {
+ gtk_text_buffer_apply_tag (view->buffer->buffer,
+ view->buffer->custom_tabs_tag,
+ &start, &end);
+ }
+ }
+}
+
static void
dialog_response_callback (GtkWidget *dialog, gint response_id, gpointer data)
{
{ "/_Attributes", NULL, 0, 0, "<Branch>" },
{ "/Attributes/Editable", NULL, do_apply_editable, TRUE, NULL },
{ "/Attributes/Not editable", NULL, do_apply_editable, FALSE, NULL },
+ { "/Attributes/Custom tabs", NULL, do_apply_tabs, FALSE, NULL },
+ { "/Attributes/Default tabs", NULL, do_apply_tabs, TRUE, NULL },
{ "/_Test", NULL, 0, 0, "<Branch>" },
{ "/Test/_Example", NULL, do_example, 0, NULL },
};
create_buffer (void)
{
Buffer *buffer;
-
+ PangoTabArray *tabs;
+
buffer = g_new (Buffer, 1);
buffer->buffer = gtk_text_buffer_new (NULL);
buffer->found_text_tag = gtk_text_buffer_create_tag (buffer->buffer, NULL);
gtk_object_set (GTK_OBJECT (buffer->found_text_tag),
"foreground", "red", NULL);
+
+ tabs = pango_tab_array_new_with_defaults (4,
+ TRUE,
+ PANGO_TAB_LEFT, 10,
+ PANGO_TAB_LEFT, 30,
+ PANGO_TAB_LEFT, 60,
+ PANGO_TAB_LEFT, 120);
+
+ buffer->custom_tabs_tag = gtk_text_buffer_create_tag (buffer->buffer, NULL);
+ gtk_object_set (GTK_OBJECT (buffer->custom_tabs_tag),
+ "tabs", tabs,
+ "foreground", "green", NULL);
+
+ pango_tab_array_free (tabs);
buffers = g_slist_prepend (buffers, buffer);